<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



<!DOCTYPE html>
<!--[if IE 6 ]> <html class="ie6 lte_ie6 lte_ie7 lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 6 ]> <html class="lte_ie6 lte_ie7 lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 7 ]> <html class="lte_ie7 lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 8 ]> <html class="lte_ie8 lte_ie9"> <![endif]-->
<!--[if lte IE 9 ]> <html class="lte_ie9"> <![endif]-->
<!--[if (gte IE 10)|!(IE)]><!--><html><!--<![endif]-->
<head>
    <title>新建员工离职信息</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/news/page.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>

    <script src="/lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript" >
        var MYOA_JS_SERVER = "";
        var MYOA_STATIC_SERVER = "";
    </script>

    <style>

        body{
            font-size: 15px;
            font-family: 微软雅黑;
        }

        .TableBlock .TableData td, .TableBlock td.TableData {
            background: #FFFFFF;
            border-bottom: none;
            border-right: none;
            padding: 3px;
        }
        .big3{
            margin-left: 5px;
            font-family: Microsoft yahei,Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;
            margin-top: -3px;
            margin-right: 40px;
            font-size: 22px;
            color: #494d59;
            font-weight: inherit;
        }


        .btn_ .btn_style {
            background: url("../../img/save.png") no-repeat;
        }
        #rs {
            display: inline-block;
            float: left;
            width: 66px;
            height: 30px;
            text-align: center;
            margin-top: 10px;
            margin-bottom: 20px;
            padding-left: 23px;
            padding-top: 7px;
            cursor: pointer;
            font-size: 14px;
            background: url("../../img/publish.png") no-repeat;
            margin-left: 40%;
        }
        .TableData{
            font-size: 14px;
            color: #2a588c;
            /*   font-weight: bold;*/
        }
        .TableBlock tbody tr{
            height: 52px;
        }
        .TableBlock tbody tr td{
            border: 1px solid #c0c0c0;
        }
        .TableBlock{
            border: 1px #124164 solid;
        }


        .TableBlock tr td:first-of-type,table tr td:nth-child(3){
            text-align: right;
        }
        .div_1{
            margin-left: 20px;
        }
        .newClass{
            float: right;
            width: 90px;
            height: 28px;
            background: #2b7fe0!important;;
            color: #fff;
            font-size: 14px;
            line-height: 28px;
            margin-right: 80px;
            cursor: pointer;
            border-radius: 5px;
        }
        .div_1 {
            margin-left: 20px;
            float: left;
        }
        input{
            float: none;
        }
        .editAndDelete3{
            color: red;
        }
        .bar {
            height: 18px;
            background: green;
        }
    </style>
</head>

<script src="../lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>


<body class="bodycolor" topmargin="5">
<table border="0" width="100%" cellspacing="0" cellpadding="3" class="small">
    <tr>
        <td>
            <div class="div_1">
                <img src="/img/commonTheme/${sessionScope.InterfaceModel}/notify_new.png" align="absmiddle"><span class="big3">新建员工离职信息</span>&nbsp;&nbsp;
            </div>
            <div class="newClass" id="newClass">
            <span style="margin-left: 30px;">
                <%--<img style="margin-right: 4px;margin-left: -11px;margin-bottom: 2px;" src="../../img/mywork/newbuildworjk.png" alt="">--%>
                返回
            </span>
            </div>
        </td>
    </tr>
</table>
<br>
<form enctype="multipart/form-data" action=""  method="post" id="form1" name="form1" onSubmit="return CheckForm();">
    <table class="TableBlock" width="90%" align="center">

        <tr>
            <td nowrap class="TableData"><span style="color: red;font-size: 16px;">*</span>离职人员：</td>
            <td class="TableData">
                <input type="text" id="userId" name="userId" style="width: 158px;height:28px;" size="12" class="BigStatic" readonly value="">&nbsp;
                <a href="javascript:;" id="departAdd" class="departAdd" ><fmt:message code="global.lang.select" /></a>
            </td>
            <td nowrap class="TableData">	担任职务：</td>
            <td class="TableData">
                <input type="text" id="position" style="width: 158px;height:28px;" name="position" size="12" maxlength="10" class="BigInput" value=""/>
            </td>
        </tr>

        <tr>
            <td nowrap class="TableData">离职类型：</td>
            <td class="TableData">
                <select name="quitType" id="quitType" style="background: white; width:170px;height: 28px;" title="">
                    <option value=""><fmt:message code="hr.th.PleaseSelect" /></option>
                    <option value="1">辞职</option>
                    <option value="2">离休</option>
                    <option value="3">退休</option>
                    <option value="4">借调</option>
                </select>
            </td>

            <td nowrap class="TableData">申请日期：</td>
            <td class="TableData">
                <input type="text" id="applicationDate" style="width: 158px;height:28px;" name="applicationDate" size="12" maxlength="10" class="BigInput" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"/>
            </td>
        </tr>

        <tr>
            <td nowrap class="TableData">拟离职日期：</td>
            <td class="TableData">
                <input type="text" id="quitTimePlan" style="width: 158px;height:28px;" name="quitTimePlan" size="12" maxlength="10" class="BigInput" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"/>
            </td>
            <td nowrap class="TableData">实际离职日期：</td>
            <td class="TableData">
                <input type="text" id="quitTimeFact" style="width: 158px;height:28px;" name="quitTimeFact" size="12" maxlength="10" class="BigInput" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"/>
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">工资截止日期：</td>
            <td class="TableData">
                <input type="text" id="lastSalaryTime" style="width: 158px;height:28px;" name="lastSalaryTime" size="12" maxlength="10" class="BigInput" value="" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"/>
            </td>

            <td nowrap class="TableData"><span style="color: red;font-size: 16px;">*</span>离职部门：</td>
            <td class="TableData">
                <input type="text" id="userIds" name="userIds" style="width: 158px;height:28px;" size="12" class="BigStatic" readonly value="">&nbsp;
                <a href="javascript:;" id="departAdds" class="departAdd" ><fmt:message code="global.lang.select" /></a>
            </td>
        </tr>


        <tr>
            <td nowrap class="TableData">离职当月薪资：</td>
            <td class="TableData">
                <input type="text" id="salary" style="width: 158px;height:28px;" name="salary" size="12" maxlength="10" class="BigInput" value=""/>
            </td>

            <td nowrap class="TableData">加入黑名单：</td>
            <td class="TableData">
                <input type="checkbox" name="isBlacklist" id="isBlacklist">
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">去向：</td><%--备注--%>
            <td class="TableData" colspan=3>
                <textarea name="trace" id="trace" cols="84" rows="3" class="BigInput" value=""></textarea>
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">离职手续办理：</td><%--备注--%>
            <td class="TableData" colspan=3>
                <textarea name="despacho" id="despacho" cols="84" rows="3" class="BigInput" value=""></textarea>
            </td>
        </tr>

        <tr>
            <td nowrap class="TableData">备注：</td><%--备注--%>
            <td class="TableData" colspan=3>
                <textarea name="remark" id="remark" cols="84" rows="3" class="BigInput" value=""></textarea>
            </td>
        </tr>

        <tr>
            <td class="blue_text TableData">
                附件文档：
            </td>
            <td colspan=3 class="files TableData" id="files_txt">
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">附件上传：</td>
            <td colspan=3 style="text-align: left">
                <forms id="uploadimgform" style="float: left;" target="uploadiframe"  action="/upload?module=hr"  method="post" >
                    <input type="file" multiple="multiple" name="file"  id="uploadinputimg"  class="w-icon5" style="position: absolute;opacity: 0;width: 70px;filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">
                    <a href="#" id="uploadimg"><img style="margin-right:5px;" src="/img/icon_uplod.png"/><fmt:message code="global.th.fileup" /></a>
                </forms>
                <div id="progress" style="width: 200px;float: left;margin-left: 10px;margin-top: 2px;">
                    <div class="bar" style="width: 0%;"></div>
                </div>
                <div class="barText" style="float: left;margin-left: 10px;"></div>
            </td>
        </tr>
        <tr>
            <td nowrap class="TableData">提醒：</td><%--备注--%>
            <td class="TableData" colspan=3 style="    padding-top: 10px;">
                <input type="hidden" name="TO_ID" id="TO_ID">
                <textarea name="remindUser" id="remindUser" cols="64" rows="3"  class="SmallStatic" wrap="yes" readonly></textarea>
                <a href="#" class="orgAdd" title='<fmt:message code="doc.th.AddReminders" />'><fmt:message code="global.lang.add" /></a><%--添加提醒人员 添加 --%>
                <a href="#" class="orgClear"  title='<fmt:message code="doc.th.EmptyReminder" />'><fmt:message code="global.lang.empty" /></a><%--清空提醒人员 清空 --%>
            </td>
        </tr>
        <tr>
            <td colspan="4" style="padding: 5px;text-align: left;font-size: 14px;color: #2a588c">
                离职原因：
                <div id="word_container" name="quitReason">

                </div>
            </td>
        </tr>

        <tr align="center" class="TableControl">
            <td colspan=4 nowrap>
                <div id="rs" type="save" class="btn_style btn_ok"><fmt:message code="global.lang.save" /></div><%--保存--%>
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">
    var type = $.GetRequest().type;
    var userId= decodeURI($.GetRequest().userId);
    ue = UE.getEditor('word_container',{elementPathEnabled : false});
    UEimgfuc();
    //返回
    $(document).on('click','.newClass',function () {
        if(type!=undefined){
            $(window.parent.document).find('.main').find('iframe').prop('src','/dimission/DimissionManager?type=1&userId='+userId)
        }else{
            $(window.parent.document).find('.main').find('iframe').prop('src','/dimission/DimissionManager')
        }
    })
    var user_id;
    var dept_id;
    //时间控件调用
    var start = {
        format: 'YYYY-MM-DD',
        /* min: laydate.now(), //设定最小日期为当前日期*/
        /* max: '2099-06-16 23:59:59', //最大日期*/
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        format: 'YYYY-MM-DD',
        /*min: laydate.now(),*/
        /*max: '2099-06-16 23:59:59',*/
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };


    function selectNumber(name,val){
        var numbers = $("select[name="+name+"]").find("option"); //获取select下拉框的所有值
        console.log(numbers.length)

        for (var j = 1; j < numbers.length; j++) {
            if ($(numbers[j]).val() == val) {
                $(numbers[j]).attr("selected", "selected");
            }
        }
    }

    // 提醒
    $('.orgAdd').click(function(){
        user_id="remindUser";
        $.popWindow("../../common/selectUser");
    });

    //提醒清空
    $('.orgClear').click(function(){
        $('#remindUser').attr("dataid","");
        $('#remindUser').attr("user_id","");
        $('#remindUser').attr("username","");
        $('#remindUser').attr("userprivname","");
        $('#remindUser').val("");
    });



    $(function () {


//        获取编辑id回显数据
        var id=$.getQueryString('id');

        if(id){
            $.ajax({
                url: "/hr/leave/leaveDetails",
                type: "get",
                data: {
                    'leaveId': id
                },
                dataType: 'json',
                success: function (obj) {
                    var data=obj.object;

                    var arr = data.attachmentList;
                    var str1=""
                    if (data.attachmentList != '' & data.attachmentList != undefined) {
                        for (var i = 0; i < (arr.length); i++) {
                            str1+='<div class="dech" deUrl="'+encodeURI(arr[i].attUrl)+'" style="display:block;"><a class="ATTACH_a" NAME="'+arr[i].attachName+'*" href="<%=basePath %>download?'+encodeURI(arr[i].attUrl)+'">'+arr[i].attachName+'</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="../img/file/icon_deletecha_03.png"/><input type="hidden" NAME="'+arr[i].attachName+'*"  class="inHidden" value="'+arr[i].aid+'@'+arr[i].ym+'_'+arr[i].attachId+',"></div>';
                        }
                        $('#files_txt').append(str1);
                    };

                    $('#userId').attr('user_id',data.leavePerson);
                    $('#userId').val(data.userName);
                    $('#position').val(data.position);
                    $('#applicationDate').val(data.applicationDate);
                    $('#quitTimePlan').val(data.quitTimePlan);
                    $('#quitTimeFact').val(data.quitTimeFact);
                    $('#lastSalaryTime').val(data.lastSalaryTime);
                    $('#salary').val(data.salary);
                    $('#userIds').val(data.deptName);
                    $('#userIds').attr('deptid',data.leaveDept);

                    $('#trace').val(data.trace);
                    $('#despacho').val(data.despacho);
                    $('#certificate').val(data.certificate);
                    $('#remark').val(data.remark);
                    ue.ready(function(){
                        ue.setContent(data.quitReason);
                    })


                }
            });

            $('#rs').attr('type','edit')
        }else{
            if(type!=undefined){
                $('#userId').val(parent.userName+',');
                $('#userId').attr('user_id',userId+',');
                $('#userId').attr('dataId',userId+',');
                $('#userId').attr('userName',parent.userName+',');
            }
        }


        //选择离职人员
        $('#departAdd').click(function(){
            user_id="userId";
            $.popWindow("../../common/selectUser?0");
        })

        //选择离职部门
        $('#departAdds').click(function(){
            dept_id="userIds";
            $.popWindow("../../common/selectDept?0");
        })



        //清空
        $('.orgDepartClear').click(function(){
            $('#joinDept').attr("dataid","");
            $('#joinDept').attr("depart_id","");
            $('#joinDept').attr("deptname","");
            $('#joinDept').val("");
        })

        // 清空
        $('.orgUserClear').click(function(){
            $('#joinPerson').attr("dataid","");
            $('#joinPerson').attr("user_id","");
            $('#joinPerson').attr("userprivname","");
            $('#joinPerson').attr("username","");
            $('#joinPerson').val("");
        });

        function CheckForm(){
            if($('#userId').val()==''){
                layer.msg('离职人员不能为空',{icon:2});
                return false;
            }
            if($('#userIds').val()==''){
                layer.msg('离职部门不能为空',{icon:2});
                return false;
            }
            if($('#assessingOfficer').val()==''){ //审批人不能为空
                layer.msg('<fmt:message  code="withdraw.th.shenpi"/>',{icon:2});
                return false;
            }
            return true;
        }


        fileuploadFn('#uploadinputimg',$('#files_txt'));

        //附件上传 方法
        var timer=null;
        function fileuploadFn(formId,element) {
            $('#form1').attr('action','../upload?module=hr')

            // $('#uploadinputimg').fileupload({
            $(formId).fileupload({
                dataType:'json',
                progressall: function (e, data) {
                    var progress = parseInt(data.loaded / data.total * 100, 10);
                    $('#progress .bar').css(
                        'width',
                        progress + '%'
                    );
                    $('.barText').html(progress + '%');
                    if(progress >= 100){  //判断滚动条到100%清除定时器
                        timer=setTimeout(function () {
                            $('#progress .bar').css(
                                'width',
                                0 + '%'
                            );
                            $('.barText').html('');
                        },2000);

                    }
                },
                done: function (e, data) {
                    if(data.result.obj != ''){
                        var data = data.result.obj;
                        var str = '';
                        var str1 = '';
                        for (var i = 0; i < data.length; i++) {
                            var gs = data[i].attachName.split('.')[1];
                            if(gs == 'jsp'||gs == 'css'||gs == 'js'||gs == 'html'||gs == 'java'||gs == 'php' ){ //后缀为这些的禁止上传
                                str += '';
                                layer.alert('jsp、css、js、html、java文件禁止上传!',{},function(){
                                    layer.closeAll();
                                });
                            }else{
                                str += '<div class="dech" deUrl="' + encodeURI(data[i].attUrl)+ '"><a href="<%=basePath %>download?'+encodeURI(data[i].attUrl)+'" NAME="' + data[i].attachName + '*"><img style="margin-right:10px;" src="/img/attachment_icon.png"/>' + data[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + ',"></div>';
                            }
                        }
                        // $('.Attachment td').eq(1).append(str);
                        element.append(str);
                    }else{
                        layer.alert('添加附件大小不能为空!',{},function(){
                            layer.closeAll();
                        });
                    }
                }
            });
        }

        $('#query_uploadArr').on('click','.deImgs',function(){
            var data=$(this).parents('.dech').attr('deUrl');
            var dome=$(this).parents('.dech');
            deleteChatment(data,dome);
        })


        //附件删除
        $('#files_txt').on('click','.deImgs',function(){
            var data=$(this).parents('.dech').attr('deUrl');
            var dome=$(this).parents('.dech');
            deleteChatment(data,dome);
        })

        //删除附件
        function deleteChatment(data,element){

            layer.confirm('<fmt:message code="menuSSetting.th.isdeleteMenu" />？', {/*确定要删除吗*/
                btn: ['<fmt:message code="global.lang.ok" />','<fmt:message code="depatement.th.quxiao" />'], //按钮 /* 确定  取消*/
                title:'<fmt:message code="notice.th.DeleteAttachment" />'/*删除附件*/
            }, function(){
                //确定删除，调接口
                $.ajax({
                    type:'get',
                    url:'../delete',
                    dataType:'json',
                    data:data,
                    success:function(res){

                        if(res.flag == true){
                            layer.msg('<fmt:message code="workflow.th.delsucess" />', { icon:6});/*删除成功*/
                            element.remove();
                        }else{
                            layer.msg('<fmt:message code="lang.th.deleSucess" />', { icon:6});/*删除失败*/
                        }
                    }
                });

            }, function(){
                layer.closeAll();
            });
        }

        // 提交表单
        $("#rs").click(function(){
            var html = ue.getContent();
            var isBlacklist ='';
            $('#form1').attr('action','');
            var fileId='';
            var fileName='';
            if(CheckForm())
            {
                for(var i=0;i<$('#files_txt .inHidden').length;i++){
                    fileId+=$('#files_txt .inHidden').eq(i).val();
                    fileName+=$('#files_txt a').eq(i).attr('NAME');
                }

                if($("input[type='checkbox']").is(':checked')){
                    isBlacklist = 1
                }else {
                    isBlacklist = 0
                }

                var data = {
                    attachmentId:fileId,
                    attachmentName:fileName,
                    leavePerson: $('#userId').attr('user_id'),
                    position: $('#position').val(),
                    quitType: $('#quitType').val(),
                    applicationDate: $('#applicationDate').val(),
                    quitTimePlan:$('#quitTimePlan').val(),
                    despacho:$('#despacho').val(),
                    quitTimeFact: $('#quitTimeFact').val(),
                    lastSalaryTime: $('#lastSalaryTime').val(),
                    salary:$('#salary').val(),
                    leaveDept: $('#userIds').attr('deptid'),
                    isBlacklist: isBlacklist,
                    trace:$('#trace').val(),
                    remark:$('#remark').val(),
                    certificate:$('#certificate').val(),
                    quitReason:html
                }

                var tp = $('#rs').attr('type')
                if(tp == 'save') {
                    $.ajax({
                        type: 'post',
                        url: '/hr/leave/addLeaveInfor',
                        dataType: 'json',
                        data: data,
                        success: function (rsp) {
                            if (rsp.flag == true) {
                                layer.msg('<fmt:message code="url.th.addSuccess" />', {icon: 1});
                                /*添加成功*/
                                if(type!=undefined){
                                    window.location.href = '/dimission/DimissionManager?type=1&userId='+userId;
                                }else{
                                    parent.location.href = '/dimission/navigationBar';
                                }
                            } else {
                                layer.msg('<fmt:message code="hr.th.AddFailed" />', {icon: 2});
                                /*添加失败*/
                            }
                        }
                    })
                } else {
                    data.leaveId = id

                    $.ajax({
                        type: 'post',
                        url: '/hr/leave/leaveUpdate',
                        dataType: 'json',
                        data: data,
                        success: function (rsp) {
                            if (rsp.flag == true) {
                                layer.msg('修改成功', {icon: 1});
                                /*添加成功*/
                                if(type!=undefined){
                                    window.location.href = '/dimission/DimissionManager?type=1&userId='+userId;
                                }else{
                                    parent.location.href = '/dimission/navigationBar';
                                }


                            } else {
                                layer.msg('修改失败', {icon: 2});
                                /*添加失败*/
                            }
                        }
                    })
                }

            }
        });

    });
</script>
</body>
</html>

